<template>
  <div>
    <van-nav-bar
      title="介绍"
      right-text="确定"
      left-arrow
      @click-left="$emit('close')"
      @click-right="editIntro"
    />
    <van-field
      v-model.trim="intr"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入简介"
      show-word-limit
    />
  </div>
</template>

<script>
import { editUserInfo } from '@/api/user.js'
export default {
  name: 'IntroPup',
  props: {
    intro: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      intr: this.intro
    }
  },
  methods: {
    async editIntro () {
      if (this.intr === '') {
        return
      }
      if (this.intr === this.intro) {
        return this.$emit('close')
      }
      try {
        await editUserInfo({
          intro: this.intr
        })
        this.$emit('editIntro', this.intr)
        this.$toast('修改简介成功')
      } catch (err) {
        this.$toast('修改简介失败')
      }
    }
  }
}
</script>

<style></style>
